import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  SetMetadata,
  Query,
} from '@nestjs/common';
import { GuardService } from './guard.service';
import { CreateGuardDto } from './dto/create-guard.dto';
import { UpdateGuardDto } from './dto/update-guard.dto';
import { ApiTags, ApiOperation, ApiParam, ApiQuery } from '@nestjs/swagger';

@Controller('guard')
@ApiTags('guard模块')
export class GuardController {
  constructor(private readonly guardService: GuardService) {}

  @Post('add')
  @ApiOperation({ summary: '创建用户' })
  @ApiParam({ name: 'username', description: '用户名' })
  @ApiParam({ name: 'password', description: '密码' })
  saveUser(@Body() createGuardDto: CreateGuardDto) {
    return this.guardService.saveUser(createGuardDto);
  }

  @Get('search')
  @ApiOperation({ summary: '查询' })
  @ApiQuery({ name: 'username', description: '查询name' })
  search(@Query('username') username: string,@Query('page') page:number,@Query('size') size:number) {
    return this.guardService.search(username,page,size);
  }

  @Post('update')
  @ApiOperation({summary:'更新'})
  @ApiParam({name:'id',description:""})
  @ApiParam({name:'username',description:""})
  @ApiParam({name:'password',description:""})
  updateUser(@Body() updateData:UpdateGuardDto){
    console.log(updateData)
    return this.guardService.updateUser(updateData)
  } 

  @Post('remove')
  @ApiOperation({summary:'删除'})
  @ApiParam({name:'id',description:"删除的id"})
  remove(@Body('id') id){
    console.log(id)
    return this.guardService.remove(id)
  }
}
